package com.example.dqnm.config;

import com.example.dqnm.Interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfigurer implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    //重写方法，注册拦截器（InterceptorRegistry）
    @Override
    public void addInterceptors(InterceptorRegistry registry) {


        List<String> patterns=new ArrayList<>();
        patterns.add("/user/login");
        patterns.add("/index/**");
        patterns.add("/category/findAllcategory");
        patterns.add("/store/**");
        patterns.add("/comment/queryComments");
        //注册拦截器类，添加黑名单(addPathPatterns("/**")),‘/*’只拦截一个层级，'/**'拦截全部
        // 和白名单(excludePathPatterns("List类型参数"))，将不必拦截的路径添加到List列表中
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns(patterns);
    }
}
